/*
 *
 * Copyright 2007, 2008 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Lailaps.
 *
 * Tiberiumlabs Lailaps is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Lailaps is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.tiberiumlabs.lailaps.settings.helpers;

import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tiberiumlabs.lailaps.gui.elements.ui.PasswordFieldUI;
import org.tiberiumlabs.lailaps.gui.elements.ui.TextFieldUI;
import org.tiberiumlabs.swing.greymetal.GreyMetalTheme;

/**
 *
 * @author <a href="paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
public class LookAndFeelHelper {

    private static final Log LOG = LogFactory.getLog(LookAndFeelHelper.class);

    /**
     * This method handles all startup initialization of look and feels.
     */
    public static final void startupInitialization() {
        // WindowsLAF supported only on Windows, while GTK supported everywhere
        // but looks ass-ugly (seems to be not fully implemented)
        try {
            String os = System.getProperty("os.name");
            if (os != null && os.indexOf("Windows") != -1) {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            }
            else {
                MetalLookAndFeel.setCurrentTheme(new GreyMetalTheme());
                UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
            }
        } catch (Exception ex) {
            LOG.error("Exception while setting LookAndFeel at startup", ex);
        }

        // specific for Lailaps:
        Object[] defaults = new Object[] {
            "TextFieldUI", TextFieldUI.class.getName(),
            "PasswordFieldUI", PasswordFieldUI.class.getName()
        };
        UIManager.getDefaults().putDefaults(defaults);
    }

}
